package com.bleeth.flow.web.handler;

import cn.hutool.core.collection.CollUtil;
import com.bleeth.flow.web.model.FlowProjectModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xyz.erupt.annotation.fun.ChoiceFetchHandler;
import xyz.erupt.annotation.fun.VLModel;
import xyz.erupt.jpa.dao.EruptDao;

import java.util.ArrayList;
import java.util.List;

/**
 * @author YuePeng
 * date 2021/2/27 22:46
 */

@Component
public class FlowProjectChoiceFetchEruptJobHandler implements ChoiceFetchHandler {



    @Autowired
    private EruptDao eruptDao;

    @Override
    public synchronized List<VLModel> fetch(String[] params) {
            List<VLModel>  loadedJobHandler = new ArrayList<>();
            List<FlowProjectModel> flowProjectModelList = eruptDao.queryEntityList(FlowProjectModel.class);
            if (CollUtil.isEmpty(flowProjectModelList)) {
                return loadedJobHandler;
            }
            for (FlowProjectModel flowProjectModel : flowProjectModelList) {
                String projectName = flowProjectModel.getProjectName();
                String projectUid = flowProjectModel.getProjectUid();
                VLModel vlModel = new VLModel(projectUid, projectName);
                loadedJobHandler.add(vlModel);
            }
        return loadedJobHandler;
    }

}
